package com.yuexunit.finance.system.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.system.entity.DataSourceEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2016年8月22日 上午10:08:15
*@author wenwenlong
*类说明
*/

@Implements(DataSourceService.class)
public class DataSourceServiceImpl implements DataSourceService {

	@Override
	public Long createDataSoruce(DataSourceEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		entity.setEnabled(Boolean.FALSE);
		PersistUtil.insert(entity);
		return entity.getDataSourceId();
	}

	@Override
	public void updataDataSource(DataSourceEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public void deleteDataSource(Long dataSourceId) {
		PersistUtil.delete(DataSourceEntity.class, dataSourceId);
	}

	@Override
	public DataSourceEntity inquireDataSource(Long dataSourceId) {
		return PersistUtil.get(DataSourceEntity.class, dataSourceId);
	}

	@Override
	public PageList<DataSourceEntity> inquireDataSourcePageList(PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(DataSourceEntity.class);
		return PersistUtil.get(criteria, page);
	}

	@Override
	public List<DataSourceEntity> inquireDataSourceList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(DataSourceEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		return PersistUtil.get(criteria);
	}
}
